import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { visualizer } from 'rollup-plugin-visualizer';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react(), visualizer({ open: true })],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src'),
    },
  },
  server: {
    host: '127.0.0.1',
    open: true,
    port: 5173,
    proxy: {
      //登录和权限
      '/api': {
        target: 'http://dsq.ljc.icu:8083/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
      '/other': {
        target: 'http://dsq.ljc.icu:8080/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/other/, ''),
      },
    },
  },
  build: {
    minify: false, // 打包结果是否minify
    rollupOptions: {
      // vite打包是通过rollup来打包的
      output: {
        manualChunks: (id: string) => {
          if (id.indexOf('node_modules') > -1) {
            return 'vendor';
          }
        },
      },
    },
  },
});
